package zhoug.common.adapters.recycler.dividers;

import android.content.Context;
import android.graphics.Rect;
import android.util.TypedValue;
import android.view.View;

import zhoug.common.utils.ResourceUtils;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 设置Item之间的间距
 *
 * @Author: zhoug
 * @Date: 2024-07-11
 * @Description:
 * @deprecated  未完成封装
 */
@Deprecated
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int space;

    /**
     *
     * @param context 上下文
     * @param unit 单位{@link TypedValue#COMPLEX_UNIT_DIP}...
     * @param space 间距
     */
    public SpacesItemDecoration(Context context, int unit, int space) {
        this.space = (int) (ResourceUtils.applyDimension(context, unit, space)+0.5);
    }

    /**
     *
     * @param context 上下文
     * @param spaceDp 间距 单位dp
     */
    public SpacesItemDecoration(Context context,int spaceDp) {
        this.space = (int) (ResourceUtils.applyDimension(context, TypedValue.COMPLEX_UNIT_DIP, spaceDp)+0.5);
    }

    /**
     *
     * @param spacePx 间距 单位px
     */
    public SpacesItemDecoration(int spacePx) {
        this.space = spacePx;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;

        // Add top space only for the first item to avoid double space between items
        if (parent.getChildLayoutPosition(view) == 0) {
            outRect.top = space;
        } else {
            outRect.top = 0;
        }

    }



}
